package com.fbt.energy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.energy.entity.ProductionLine;
import com.fbt.energy.service.ProductionLineService;


import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产线表(ProductionLine)表控制层
 *
 * @author makejava
 * @since 2021-12-12 19:06:54
 */
@CrossOrigin
@RestController
@Api(tags = {"产线表(ProductionLine)表控制层"})
@RequestMapping("/productionLine")
public class ProductionLineController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ProductionLineService productionLineService;

    /**
     * 分页查询
     *
     * @param productionLine 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Log(title="产线表")
    @ApiOperation("分页查询列表")
    @GetMapping
    public ResponseEntity<Page<ProductionLine>> queryByPage(ProductionLine productionLine, PageRequest pageRequest) {
        return ResponseEntity.ok(this.productionLineService.queryByPage(productionLine, pageRequest));
    }


    @Log(title="产线表")
    @ApiOperation("通过产线编号查询单条数据")
    @GetMapping("/{productionNo}")
    public List<ProductionLine> queryById(@PathVariable("productionNo") String productionNo) {
        QueryWrapper<ProductionLine> prWrapper=new QueryWrapper<>();
        prWrapper.eq("production_no", productionNo);
        List<ProductionLine> list = productionLineService.list(prWrapper);

        return list;
    }

    /**
     * 新增数据
     *
     * @param productionLine 实体
     * @return 新增结果
     */

    @Log(title="产线表",businessType= BusinessType.INSERT)
    @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<ProductionLine> add(ProductionLine productionLine) {
        return ResponseEntity.ok(this.productionLineService.insert(productionLine));
    }

    /**
     * 编辑数据
     *
     * @param productionLine 实体
     * @return 编辑结果
     */
    @Log(title="产线表",businessType=BusinessType.UPDATE)
    @ApiOperation("修改数据")
    @PutMapping
    public ResponseEntity<ProductionLine> edit(ProductionLine productionLine) {
        return ResponseEntity.ok(this.productionLineService.update(productionLine));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Log(title="产线表",businessType=BusinessType.DELETE)
    @ApiOperation("根据主键删除数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.productionLineService.deleteById(id));
    }

}

